package com.knav.inject;

import android.app.Activity;

import com.knav.inject.Base.Constant;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;


/**
 * 注解配置的分发器 用于分发不同类型的注解 分别进行处理
 */
public class Dispatcher {


    private Class clazz;

    /**
     * 分发注解
     *
     * @param args
     */
    public void dispatcher(Class clazz, Object[]... args) {
        this.clazz = clazz;
        for (int i = 0; i < args.length; i++) {
            Object[] arg = args[i];
            if (arg instanceof Field[]) { // 字段类型的注解
                dispatcherConstants((Field[]) arg);
            } else if (arg instanceof Method[]) { // 方法类型的注解

            }
        }
    }


    public void dispatcherAppCompatActivity(Class clazz, Activity activity, Object[]... args) throws Exception {
        this.clazz = clazz;
        FindHandle findHandle = new FindHandle();
        for (int i = 0; i < args.length; i++) {
            Object[] arg = args[i];
            if (arg instanceof Field[]) { // 字段类型的注解
                findHandle.dispatcherActivitFind((Field[]) arg, activity);
            } else if (arg instanceof Method[]) { // 方法类型的注解

            }
        }
    }


    public void dispatcherActivity(Class clazz, Activity activity, Object[]... args) throws Exception {
        this.clazz = clazz;
        FindHandle findHandle = new FindHandle();
        for (int i = 0; i < args.length; i++) {
            Object[] arg = args[i];
            if (arg instanceof Field[]) { // 字段类型的注解
                findHandle.dispatcherAppCompatActivitFind((Field[]) arg, activity);
            } else if (arg instanceof Method[]) { // 方法类型的注解

            }
        }
    }

    private void dispatcherConstants(Field[] arg) {
        ConstantsHandle constantsHandle = new ConstantsHandle();
        for (Field field : arg) {
            Annotation[] annotations = field.getAnnotations();
            for (Annotation annotation : annotations) {
                if (annotation instanceof Constant) {
                    constantsHandle.DealConstanst(field, ((Constant) annotation) , clazz);
                }
            }
        }
    }





}
